import json  
  
# 读取JSON文件内容  
with open('postgres-96_knobs.json', 'r') as file:  
    json_data = file.read()  
  
# 将JSON字符串转换为Python对象（这里假设它是一个列表）  
data = json.loads(json_data)  
  
# 初始化计数器  
context_user_count = 0  
context_postmaster_count = 0  
context_sighup_count = 0  
context_internal_count = 0
context_superuser_count = 0
context_superuser_backend_count = 0
count = 0
  
# 遍历JSON对象中的每个元素  
for item in data:  
    # 检查每个元素的'context'值  
    if item['fields']['context'] == 'user':  
        context_user_count += 1  
    elif item['fields']['context'] == 'postmaster':  
        context_postmaster_count += 1  
    elif item['fields']['context'] == 'sighup':  
        context_sighup_count += 1  
    elif item['fields']['context'] == 'internal':  
        context_internal_count += 1  
    elif item['fields']['context'] == 'superuser':  
        context_superuser_count += 1  
    elif item['fields']['context'] == 'superuser-backend':  
        context_superuser_backend_count += 1  
    else:
        print(str(item['fields']['context']))
    count += 1
  
# 打印结果
print('user:', context_user_count)  
print('postmaster:', context_postmaster_count)
print('sighup:', context_sighup_count)
print('internal:', context_internal_count)
print('superuser:', context_superuser_count)
print('superuser-backend:', context_superuser_backend_count)
print('count:', count)
